package com.newenergy.wisehome.ui.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.newenergy.wisehome.R;
import com.newenergy.wisehome.config.AppManager;
import com.newenergy.wisehome.data.bean.DeviceCategory;

import butterknife.BindView;
import butterknife.OnClick;
import me.yokeyword.fragmentation.ISupportFragment;

/**
 * Created by kyx on 2018/4/27.
 * 电暖器操作页面--7204
 */

public class ElectricHeaterFragment extends BaseFragment {

    private static String ARG_ELECTRICHEATER="arg_electricheater";
    @BindView(R.id.btn_back)
    Button mBtnBack;
    @BindView(R.id.tv_back)
    TextView mTvBack;
    @BindView(R.id.tv_page)
    TextView mTvPage;
    @BindView(R.id.btn_electricheater_switch)
    Button mBtnElectricheaterSwitch;
    @BindView(R.id.btn_electricheater_function)
    Button mBtnElectricheaterFunction;
    @BindView(R.id.btn_electricheater_timing)
    Button mBtnElectricheaterTiming;
    @BindView(R.id.btn_electricheater_shake)
    Button mBtnElectricheaterShake;
    @BindView(R.id.btn_electricheater_tem_add)
    Button mBtnElectricheaterTemAdd;
    @BindView(R.id.btn_electricheater_cut)
    Button mBtnElectricheaterCut;

    protected DeviceCategory mDeviceCategory;
    

    @Override
    public int getLayoutId() {
        return R.layout.fragment_electricheater;
    }


    public static ISupportFragment newInstance(DeviceCategory mainItem) {
        Bundle args = new Bundle();
        args.putParcelable(ARG_ELECTRICHEATER, mainItem);
        ElectricHeaterFragment fragment = new ElectricHeaterFragment();
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    public void init(View rootView) {
        mDeviceCategory = getArguments().getParcelable(ARG_ELECTRICHEATER);
        mTvPage.setText(mDeviceCategory.getName());
    }

    @Override
    public void onResume() {
        super.onResume();
        if (mDeviceCategory != null) {
            AppManager.getInstance(getContext()).mSelectDeviceCategory = mDeviceCategory;
        }
    }

    @OnClick({R.id.btn_back, R.id.tv_back, R.id.btn_electricheater_switch, R.id.btn_electricheater_function, R.id.btn_electricheater_timing, R.id.btn_electricheater_shake, R.id.btn_electricheater_tem_add, R.id.btn_electricheater_cut})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_back:
                doBack();
                break;
            case R.id.tv_back:
                doBack();
                break;
            case R.id.btn_electricheater_switch:
                AppManager.getInstance(mainActivity).commandAdvertise("01",mDeviceCategory.getFamilyId(),mDeviceCategory.getGroupId(),"01000000","000000",mCurrFamily.getSeed(),mCurrFamily.getFeedback(),1,"7204");

                break;
            case R.id.btn_electricheater_function:
                AppManager.getInstance(mainActivity).commandAdvertise("01",mDeviceCategory.getFamilyId(),mDeviceCategory.getGroupId(),"02000000","000000",mCurrFamily.getSeed(),mCurrFamily.getFeedback(),1,"7204");

                break;
            case R.id.btn_electricheater_timing:
                AppManager.getInstance(mainActivity).commandAdvertise("01",mDeviceCategory.getFamilyId(),mDeviceCategory.getGroupId(),"03000000","000000",mCurrFamily.getSeed(),mCurrFamily.getFeedback(),1,"7204");

                break;
            case R.id.btn_electricheater_shake:
                AppManager.getInstance(mainActivity).commandAdvertise("01",mDeviceCategory.getFamilyId(),mDeviceCategory.getGroupId(),"04000000","000000",mCurrFamily.getSeed(),mCurrFamily.getFeedback(),1,"7204");

                break;
            case R.id.btn_electricheater_tem_add:
                AppManager.getInstance(mainActivity).commandAdvertise("01",mDeviceCategory.getFamilyId(),mDeviceCategory.getGroupId(),"05000000","000000",mCurrFamily.getSeed(),mCurrFamily.getFeedback(),1,"7204");

                break;
            case R.id.btn_electricheater_cut:
                AppManager.getInstance(mainActivity).commandAdvertise("01",mDeviceCategory.getFamilyId(),mDeviceCategory.getGroupId(),"06000000","000000",mCurrFamily.getSeed(),mCurrFamily.getFeedback(),1,"7204");

                break;
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mDeviceCategory = null;
    }


}
